<template>
  <ContentWrap>
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="专场名称" prop="eventName">
        <el-input
          clearable
          v-model="queryParams.eventName"
          placeholder="请输入专场名称"
          @keyup.enter="handleQuery"
          :maxlength="50"
          class="!w-200px"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select clearable v-model="queryParams.status" placeholder="请选择" class="!w-200px">
          <el-option
            v-for="dict in getIntDictOptionsFn(dict_type.BID_STATUS_TYPE)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="交易日期" prop="tradingDate">
        <el-date-picker
          v-model="queryParams.tradingDate"
          value-format="YYYY-MM-DD"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          type="daterange"
          class="!w-250px"
        />
      </el-form-item>

      <el-form-item>
        <el-button @click="handleQuery">
          <Icon icon="ep:search" class="mr-5px" />
          搜索
        </el-button>
        <el-button @click="resetQuery">
          <Icon icon="ep:refresh" class="mr-5px" />
          重置
        </el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>
  <ContentWrap>
    <!-- 列表 -->
    <el-table
      v-loading="loading"
      :data="list"
      border
      stripe
      :header-cell-style="{ background: '#F3F4F7', color: '#555' }"
    >
      <el-table-column label="编号" align="center" prop="eventCode" width="180" fixed="left" />
      <el-table-column
        label="专场名称"
        align="center"
        prop="eventName"
        width="180"
        fixed="left"
        :show-overflow-tooltip="true"
      >
        <template #default="scope">
          <span class="text-blue-500" @click="openForm(1, scope.row.id)">
            {{ scope.row.eventName }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" width="100">
        <template #default="scope">
          <dict-tag :type="dict_type.BID_STATUS_TYPE" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column
        label="交货地煤源"
        align="center"
        prop="deliveryPlace"
        width="150"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="交易总量(吨)" align="center" prop="tradingGrossAmount" width="120" />
      <el-table-column label="保证金(元)" align="center" prop="securityDeposit" width="120">
      </el-table-column>
      <el-table-column
        label="交货周期"
        align="center"
        prop="deliveryCycle"
        width="250"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="交易日期"
        align="center"
        prop="deliveryDate"
        width="150"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="交易时间"
        align="center"
        prop="deliveryTime"
        width="150"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="倒计时(秒)" align="center" prop="countdown"> </el-table-column>
    </el-table>
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>
</template>
<script setup lang="ts">
import * as announceManage from '@/api/announceManage'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
const dict_type = ref(DICT_TYPE)
const getIntDictOptionsFn = ref(getIntDictOptions)
const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  eventName: undefined,
  status: undefined,
  tradingDate: []
})
const queryFormRef = ref()
const emit = defineEmits(['subPage'])

/** 查询列表 */

const getList = async () => {
  loading.value = true
  try {
    const data = await announceManage.getTableList(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

const openForm = (index: number, id?: number) => {
  emit('subPage', index, id)
}

/** 初始化 **/
onMounted(() => {
  getList()
})

defineExpose({ openForm })
</script>
<style scoped>
.text-blue-500 {
  color: #3b82f6;
  cursor: pointer;
}
</style>
